package org.ly.uap.client.ssl;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class WhitelistHostnameVerifier
        implements HostnameVerifier {
    private String[] allowedHosts;

    public WhitelistHostnameVerifier(String[] allowed) {
        this.allowedHosts = allowed;
    }

    public WhitelistHostnameVerifier(String allowedList) {
        this.allowedHosts = allowedList.split(",\\s*");
    }

    public boolean verify(String hostname, SSLSession session) {
        for (String allowedHost : this.allowedHosts) {
            if (hostname.equalsIgnoreCase(allowedHost)) {
                return true;
            }
        }
        return false;
    }
}
